# app init
from flask import Flask

app = Flask(__name__)
app.config.from_object('config')

#: db  init
from model import db

db.init_app(app)

#: api init  -> 先加载 resource ,再初始化
from flask_restful import Api

#: 定义错误信息
errors = {
	'UserAlreadyExistError':{
	'message': "A user with that username already exits.",
	'status': 409,
	},
	
	'ResourceDoesNotExist':{
	'message': "A resource with that ID no longer exist.",
	'status': 410,
	'extra': "Any extra information"
	}
}

api = Api(catch_all_404s=True, errors=errors)

#: 添加资源
from util_resource import Demo, Users

api.add_resource(Demo, '/', '/hello')
api.add_resource(Users, '/users/<int:userId>')
api.init_app(app)


#: Run
if __name__ == '__main__':
	app.run( debug=True )
